<template>
  <div>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <!-- :data-source="tableData" -->
      <!-- :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
      <list-table
        ref="table"
        :loading="loading"
        :pagination="false"
        :export-config="{ use: true,select: '物资招标计划汇总导出选中',all: '物资招标计划汇总导出全部'}"
        :columns="columns"
        :request="loadData"
        row-key="id"
      >
        <span
          slot="index"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <div
          slot="operation"
          slot-scope="text, record, index"
          class="pub-table-list-action"
        >
          <span @click="handleEdit(record, 3)">查看</span>
          <approval-button
            :id="record.id"
            :status="record.auditStatus"
            v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' "
          />
        </div>
      </list-table>
    </a-card>
  </div>
</template>
<script>
import { selectOption } from '@/api/material/goods/goods'
import { collectList } from '@/api/material/procurement/plan'
import SelectProject from '@/components/Select/SelectProject'
import SelectSubCompany from '@/components/Select/SelectSubCompany'

export default {
	name:'a'+Date.now(),
    data: function() {
        return {
            queryParam: {},
            loading:false,
            pageNo: 1,
            pageSize: 10,
            totalSize: 0,
           statistics: {},
            searchArr: [
                // 搜索框
                {
                    name: '所属分公司',
                    valueKey: 'branchCompanyId',
                    type: SelectSubCompany
                },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },
                {
                    name: '物资名称',
                    value: 'materialName',
                    type: 'input'
                },
                {
                    name: '物料编码',
                    value: 'materialCode',
                    type: 'input'
                },

                {
                    name: '招标计划编码',
                    value: 'tenderCode',
                    type: 'input'
                },
                {
                    name: '工程名称',
                    value: 'wbsId',
                    type: 'select',
                    data: []
                }
            ],
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    scopedSlots: { customRender: 'index' },
                    width: 70
                },{
                    title: '所属分公司',
                    dataIndex: 'branchCompany',
                    width:150
                },
                {
                    title: '物资名称',
                    dataIndex: 'materialName',
                    width: 120
                },
                {
                    title: '物料编码',
                    dataIndex: 'materialCode',
                    width: 160
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName',
                    width: 120
                },
                {
                    title: '数量',
                    dataIndex: 'num',
                    width: 120
                },
                {
                    title: '概算金额',
                    dataIndex: 'price',
                    width: 120
                },
                {
                    title: '计划招标时间',
                    dataIndex: 'planDate',
                    width: 120
                },
                {
                    title: '物资招标计划编码',
                    dataIndex: 'tenderCode',
                    width: 160
                },
                {
                    title: '工程名称',
                    dataIndex: 'wbsName',
                    width: 120
                },
                {
                    title: '起始时间',
                    dataIndex: 'startDate',
                    width: 120
                },
                {
                    title: '截止时间',
                    dataIndex: 'endDate',
                    width: 120
                },
                {
                    title: '创建人',
                    dataIndex: 'creatorName',
                    width: 160
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    width: 160
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    scopedSlots: { customRender: 'operation' },
                    width: 160,
                    fixed:'right'
                }
            ],
            selectedRowKeys: [],
            selectId: [],
            selectedRows: [],
            chooseData: 0,
            tableData: [],
           loadData: async parameter => {
            this.loading = true;
             const requestParameters = Object.assign({}, parameter, this.queryParam)
             return collectList(requestParameters).then((res) => {
                 this.loading = false;
                 return res;
             })
            },
        }
    },
    mounted: function() {
        this.getProgramme()
    },
    methods: {
        getProgramme: function() {
            let _this = this
            selectOption({
                type: 18
            }).then(res => {
                if (res.code === 200) {
                    for (let i = 0; i < res.data.length; i++) {
                        _this.searchArr[5].data.push({ label: res.data[i].name, value: res.data[i].id })
                    }
                }
            })
        },
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        handleEdit(record, state) {
            this.$router.push({
                path: '/material/procurement/planAdd',
                query: {
                    id: record && record.tenderPlanId || '',
                    state: state
                }
            })
        }
    }
}
</script>
